package com.lc.luzhengtang.adapter;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.activity.PhotoShowActivity;
import com.lc.luzhengtang.bean.ShopDetailBean;
import com.lc.luzhengtang.conn.Conn;
import com.lc.luzhengtang.imgloader.GlideCircleTransform;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Jaeger on 16/2/24.
 * <p>
 * Email: chjie.jaeger@gmail.com
 * GitHub: https://github.com/laobie
 */
public class PostAdapter2 extends BaseQuickAdapter<ShopDetailBean.DataBeanX.EvaluateBean.DataBean, BaseViewHolder> {

    RecyclerView recyclerView_photolist;
    GridView layout_grid;

    public PostAdapter2(List<ShopDetailBean.DataBeanX.EvaluateBean.DataBean> data) {
        super(R.layout.item_evaluate, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, final ShopDetailBean.DataBeanX.EvaluateBean.DataBean item) {
        ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) helper.convertView);
        if (item.getEvaluate().equals("1")) {
            helper.setText(R.id.text_newstitle, "好评");
        } else if (item.getEvaluate().equals("2")) {
            helper.setText(R.id.text_newstitle, "中评");
        } else {
            helper.setText(R.id.text_newstitle, "差评");
        }

        helper.setText(R.id.text_newstime, item.getUsername());

        helper.setText(R.id.text_tiem, item.getCreate_time());

        helper.setText(R.id.text_content, item.getContent());

        Glide.with(mContext).load(Conn.HOST3 + item.getAvatar()).transform(new GlideCircleTransform(mContext)).error(R.mipmap.touxiang).placeholder(R.mipmap.touxiang).into((ImageView) helper.getView(R.id.img_person));
        recyclerView_photolist = helper.getView(R.id.recyclerView_photolist);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 4);

        recyclerView_photolist.setLayoutManager(gridLayoutManager);
        gridLayoutManager.setAutoMeasureEnabled(true);
        if (item.getPicarr().isEmpty()) {
            recyclerView_photolist.setVisibility(View.GONE);
        } else {

            ItemPicAdapter itemPicAdapter = new ItemPicAdapter(item.getPicarr());
            recyclerView_photolist.setAdapter(itemPicAdapter);
            itemPicAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Intent intent = new Intent();
                    //intent.putExtra("url", urlspic.get(position));‘
                    intent.putExtra("position", position);
                    intent.putStringArrayListExtra("mImages", (ArrayList<String>) item.getPicarr());
                    intent.setClass(mContext, PhotoShowActivity.class);
                    mContext.startActivity(intent);

                }
            });


        }
/*
        layout_grid = helper.getView(R.id.layout_grid);
        MyGridAdapter myGridAdapter = new MyGridAdapter(mContext, item.getPicarr());


        layout_grid.setAdapter(myGridAdapter);*/


    }
}
